import {BASE_URL,ID,KEY} from '../config/index.js'

function http({url,method="GET",data={}}){
  return new Promise((resolve,reject)=>{
    uni.request({
      url:BASE_URL+url,
      method,
      data,
      header:{
        'X-LC-Id': ID, //此处必须使用自己的ID
        'X-LC-Key': KEY,  //此处必须使用自己的Key
        'Content-Type': 'application/json'
      },
      success:(res)=>{
        resolve(res)   //交给then
      },
      fail:(err)=>{
        reject(err)  //交给catch
      }
    })
  })
}

function get(url,data){
  return http({url,method:'GET',data})
}

function post(url,data){
  return http({url,method:'POST',data})
}

function del(url,data){
  return http({url,method:'DELETE',data})
}

export {
  http,
  get,
  post,
  del
}